package util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import models.service;

public class AddandSort {

	public List<service> temp = new ArrayList<service>();
	
	//add all the name starts with ch into a arraylist
	public List<service> dosplit(List<service> services,char ch){
		List<service> current = new ArrayList<service>();
		
		for(int i =0; i< services.size();i++){
			if(services.get(i).getName().toUpperCase().charAt(0) == ch ){
				current.add(services.get(i));
				temp.remove(services.get(i));
			}
		}
		return current;
	}
	
	public List<List<service>> doSortandAdd(List<service> services){
		
		for(int i =0; i< services.size();i++){
			temp.add(services.get(i));
		}
		
		Collections.sort(services,new SrvComparetor());
		List<List<service>> aTOz = new ArrayList<List<service>>();
		for(int i=65;i<=90;i++){
			List<service> current = new ArrayList<service>();
			current = dosplit(services,(char)i);
			aTOz.add(current);
		}
		aTOz.add(temp);
		return aTOz;
	}
	
}
